package cn.yj.frame.spring.event;

import cn.yj.frame.netty.NettyServer;
import cn.yj.register.RegisterConfig;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;

/**
 * 在上下文关闭的时候注册服务 - 服务停止
 *
 * @author 永健
 * @since 2022-01-19 10:23
 */
public class NettyApplicationCloseListener implements ApplicationListener<ContextClosedEvent> {

	@Override
	public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
		String host = contextClosedEvent.getApplicationContext().getEnvironment().getProperty("spring.rpc.host");
		RegisterConfig.getInstance().logout(host);
		// 关闭netty
		NettyServer.closeServer();
	}
}
